import * as THREE from "three";

const FenceGlowShader = {
  shaderID: 'FenceGlowShader',

  uniforms: {
    'iTime': { value: 1.0 },
    'height': { value: new THREE.Vector2(0,1) },
    'fenceColor': { type: 'c', value: new THREE.Color('#55bb5f') }
  },

  vertexShader: /* glsl */`
  varying float zVal;
  uniform vec2 height;
  
  void main() {
    zVal = position.z - height.x;
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  }`,

  fragmentShader: /* glsl */`
	uniform vec3 fenceColor;
	uniform vec2 height;
  uniform float iTime;
  varying float zVal;
 
  void main() {
    float uvY = zVal / (height.y - height.x);
    float ratio = pow(1.0 - uvY, iTime); // sqrt(vUv.y);
    // float ratio = vUv.y;
    vec4 topColor = vec4(fenceColor, 0.0);
    vec4 bottomColor = vec4(fenceColor, 1.0);
    vec4 color = mix(topColor, bottomColor, ratio);
    gl_FragColor = color; // vUv.y
  }
`
}

export default FenceGlowShader;
